﻿#pragma execution_character_set("utf-8")
#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "database.h"
QString MainWidget::currentUser = "";

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    DataBasePri db;
    setFixedSize(445,348);
    setWindowTitle("东北石油大学校园导航");
    m_LoginWidget       = new LoginWidget(this);
    m_ResigerWidget     = new ResigerWidget(this);
    m_AdminWidget       = new AdminWidget(this);
    m_ChangeWidget      = new ChangeWidget(this);
    m_ManageWidget      = new ManageWidget(this);
    m_CenterWidget      = new CenterWidget(this);
    m_CoreDisWidget     = new CoreDisWidget(this);

    ui->stackedWidget->addWidget(m_LoginWidget);
    ui->stackedWidget->addWidget(m_ResigerWidget);
    ui->stackedWidget->addWidget(m_AdminWidget);
    ui->stackedWidget->addWidget(m_ChangeWidget);
    ui->stackedWidget->addWidget(m_ManageWidget);
    ui->stackedWidget->addWidget(m_CenterWidget);
    ui->stackedWidget->addWidget(m_CoreDisWidget);

    ui->stackedWidget->setCurrentWidget(m_LoginWidget);

    connect(m_LoginWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ResigerWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_AdminWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ChangeWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ManageWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_CenterWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_CoreDisWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));


}

MainWidget::~MainWidget()
{
    delete ui;
}

void MainWidget::resizeEvent(QResizeEvent *event)
{
    int m_width = this->width();
    int m_height = this->height();
    ui->stackedWidget->setGeometry(0,0,m_width,m_height);
}

void MainWidget::setWidget(QString str)
{
    // 先阻止所有可能的重置大小
    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    if(str == "m_LoginWidget"){
        setFixedSize(445,348);
        ui->stackedWidget->setCurrentWidget(m_LoginWidget);
    }
    if(str == "m_ResigerWidget"){
        setFixedSize(600,420);
        ui->stackedWidget->setCurrentWidget(m_ResigerWidget);
    }
    if(str == "m_AdminWidget"){
        setFixedSize(500,300);   // 管理员窗口大小
        ui->stackedWidget->setCurrentWidget(m_AdminWidget);
    }
    if(str == "m_ManageWidget"){
        setFixedSize(900,700);    // 管理窗口大小
        ui->stackedWidget->setCurrentWidget(m_ManageWidget);
    }
    if(str == "m_ChangeWidget"){
        setFixedSize(350,400);    // 修改窗口大小
        ui->stackedWidget->setCurrentWidget(m_ChangeWidget);
    }
    if(str == "m_CenterWidget"){
        setFixedSize(1200,1100);
        ui->stackedWidget->setCurrentWidget(m_CenterWidget);
    }
    if(str == "m_CoreDisWidget"){
        setFixedSize(1053,992);
        ui->stackedWidget->setCurrentWidget(m_CoreDisWidget);
    }
    adjustSize();  // 统一调用一次调整大小
    updateGeometry();  // 强制更新几何属性
}
